
#include "khan.hpp"
#include <string.h>

bool kstrtok(const std::string& str, const std::string& delim, string_vector& vec)
{
    char*   pcstr  = strdup(str.c_str());
    char*   ptmp = pcstr;
    char*   ptok = NULL;
    char*   psaveptr = NULL;
    std::string     tstr;

//    PDBG("input: %s\n", pcstr);
    if (!pcstr) return false;
    while (1) { 
        ptok = strtok_r(ptmp, delim.c_str(), &psaveptr);
        if (ptok == NULL) break;
 //       PDBG("tok: %s\n", ptok);

        ptmp = NULL;
        tstr = ptok;
        vec.push_back(tstr);
    }
    free(pcstr);
    return true;
}

